

  <title>用户与角色管理</title>

  <div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
      <a lay-href="">主页</a>
      <a><cite>权限中心</cite></a>
      <a><cite>用户与角色管理</cite></a>
    </div>
  </div>
  
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">用户与角色管理</div>
          <div class="layui-card-body">
            <blockquote class="layui-elem-quote">点击下面表格，修改用户与角色关系</blockquote>
            <table class="layui-hide" id="test-table-demoEvent" lay-filter="test-table-demoEvent"></table>
			
			
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <div class="site-text" style="margin: 5%; display: none" id="window1"  target="test1">
  	
  		<div class="layui-card" >
  			<div class="layui-card-header"></div>
  			<div class="layui-card-body">
				
  				<input type = "hidden"  id="accId" name="accId" lay-verify="accId" autocomplete="off" placeholder="" class="layui-input">
				<table class="layui-hide" id="test-table-toolbar" lay-filter="test-table-toolbar" ></table>
				<script type="text/html" id="test-table-toolbar-toolbarDemo">
				  <div class="layui-btn-container">
				    <button class="layui-btn layui-btn-sm" lay-event="updateAccRole">修改用户与角色关系</button>
				    
				  </div>
				</script>
				<div class="layui-btn-container">
  				<div class="layui-form-item">
  				  
  				</div>
  			</div>
  			</div>
  		</div>

  </div>
  
  <script>
  layui.use(['admin', 'table'], function(){
    var table = layui.table;
    
    table.render({
      elem: '#test-table-demoEvent'
      ,height: 313
      ,url: path + '/authority/AccRel/selectAccountByRole'
      ,cols: [[
        {field:'loginName', title: '用户名', width:80}
        ,{field:'lastLoginTime', title: '最后登录时间', width:160}
        ,{field:'schNm', title: '学校名称', width:120, event: 'setSign', style:'cursor: pointer;'}
        ,{field:'addTime', title: '数据添加时间',width:150}
        ,{field:'addUserId', title: '数据添加人',width:120}
      ]]
    });
	table.render({
		elem: '#test-table-toolbar'
		,url: path + '/authority/Role/selectAll'
		,toolbar: '#test-table-toolbar-toolbarDemo'
		,title: '角色数据表'
		,cols: [[
			{type: 'checkbox', fixed: 'left'}
			,{field:'roleId', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, hide:true}
			,{field:'roleNm', title:'角色名称', width:120}
			,{field:'roleDesc', title:'描述', width:300}
			,{field:'schNm', title:'院校名称', width:120}
			,{field:'roleStatic', title:'角色状态', width:120, sort: true, templet: function(d){    //动态显示数据
				if(d.roleStatic == 1)
				{
					return '<span style="color:#0000FF;">' + '有效' + '</span>'
				}
				else
				{
					return '<span style="color:red;">' + '无效' + '</span>'
				}
			}}
			,{field:'addTime', title:'数据添加时间', width:150}
			,{field:'addUserId', title:'数据添加人', width:120}
		]]
		,request: {
			pageName: 'pageCurrent',  //当前页数
			limitName: 'pageSize'     //每页显示数据笔数
		}
		,limit: 5
		,limits: [5,10,15]
		,page: true
	});
    //监听单元格事件
    table.on('tool(test-table-demoEvent)', function(obj){
      var data = obj.data;
	  $("#accId").val(data.accId);
      if(obj.event === 'setSign'){
      		
      		
        layer.open({
        	title: '角色与菜单关系'
        	,area: ['800px', '600px']
        	,skin: 'layui-layer-molv'
        	,shadeClose: true
        	,type:1
        	,shade: 0 //遮罩透明度
        	,content: $("#window1")
			,done:layui.form.render()
        });
      }
    });
	
	
	
	
	table.on('toolbar(test-table-toolbar)', function(obj){
	  var checkStatus = table.checkStatus(obj.config.id);
	  switch(obj.event){
	    case 'updateAccRole':
			var data = checkStatus.data;
			var Ids = new Array();
			var i = 0;
			var j =0;
			getCheck(data);
			var ids = Ids.toString();
			function getCheck(data){ 
			   for(i = 0;i< data.length ;i++){
					Ids.push(data[i].roleId)
				}
				
			}
			$.post({
			   url: path +"/authority/AccRel/updateAccRel",
			   data:{
				  
				   userId:1
				   ,accId:$("#accId").val()
				   , roleIds:ids
			   },
			   success:function(res){
				   if(res.code == 0){
					   layer.msg("修改成功");
					   layer.closeAll();
				   }else{
					   layer.msg("修改失败");
				   }
			   }
					   
			})
	    break;
	  };
	  });
  });
  </script>